#include "apue.h"
#include <fcntl.h>

void set_fl(int fd, int flags){
	int val;

	val = fcntl(fd, F_GETFL, 0);
	if(val == -1)
		err_sys("fcntl F_GETFL error");
	val |= flags;
	printf("val:%d ", val);
	if(fcntl(fd, F_SETFL, val) < 0)
		err_sys("fcntl F_SETFL error");
	#if defined(O_SYNC)
                if((fcntl(fd, F_GETFL, 0)) & O_SYNC)
                        printf("after: sync\n");
                else 
                        printf("after: not sync\n");
        #endif
	
}

int main(void){
	int fd;
	int val;	

	fd = open("file.hole", O_RDONLY);
	val = fcntl(fd, F_GETFL, 0);
	#if defined(O_SYNC)
		if(val & O_SYNC)
			printf("before: sync\n");
		else
			printf("before: not sync\n");
	#endif
	set_fl(fd, O_SYNC);
	val = fcntl(fd, F_GETFL, 0);
	exit(0);
}
